package com.lightboat.web.controller.crm;

import com.lightboat.common.annotation.Log;
import com.lightboat.common.core.controller.BaseController;
import com.lightboat.common.core.domain.AjaxResult;
import com.lightboat.common.core.page.TableDataInfo;
import com.lightboat.common.enums.BusinessType;
import com.lightboat.common.utils.poi.ExcelUtil;
import com.lightboat.system.domain.CrmUserFollowRelation;
import com.lightboat.system.service.ICrmUserFollowRelationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户跟进关系Controller
 *
 * @author lightboat
 * @date 2025-08-22
 */
@Tag(name = "用户跟进关系")
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/follow/relation")
public class CrmUserFollowRelationController extends BaseController {

    private final ICrmUserFollowRelationService crmUserFollowRelationService;

    /**
     * 查询用户跟进关系列表
     */
    @Operation(summary = "查询用户跟进关系列表")
    @PreAuthorize("@ss.hasPermi('system:relation:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmUserFollowRelation crmUserFollowRelation) {
        startPage();
        List<CrmUserFollowRelation> list = crmUserFollowRelationService.selectCrmUserFollowRelationList(crmUserFollowRelation);
        clearPage();
        return getDataTable(list);
    }

    /**
     * 导出用户跟进关系列表
     */
    @Operation(summary = "导出用户跟进关系列表")
    @PreAuthorize("@ss.hasPermi('system:relation:export')")
    @Log(title = "用户跟进关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmUserFollowRelation crmUserFollowRelation) {
        List<CrmUserFollowRelation> list = crmUserFollowRelationService.selectCrmUserFollowRelationList(crmUserFollowRelation);
        ExcelUtil<CrmUserFollowRelation> util = new ExcelUtil<CrmUserFollowRelation>(CrmUserFollowRelation.class);
        util.exportExcel(response, list, "用户跟进关系数据");
    }

    /**
     * 获取用户跟进关系详细信息
     */
    @Operation(summary = "获取用户跟进关系详细信息")
    @PreAuthorize("@ss.hasPermi('system:relation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(crmUserFollowRelationService.selectCrmUserFollowRelationById(id));
    }

    /**
     * 新增用户跟进关系
     */
    @Operation(summary = "新增用户跟进关系")
    @PreAuthorize("@ss.hasPermi('system:relation:add')")
    @Log(title = "用户跟进关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmUserFollowRelation crmUserFollowRelation) {
        return toAjax(crmUserFollowRelationService.insertCrmUserFollowRelation(crmUserFollowRelation));
    }

    /**
     * 修改用户跟进关系
     */
    @Operation(summary = "修改用户跟进关系")
    @PreAuthorize("@ss.hasPermi('system:relation:edit')")
    @Log(title = "用户跟进关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmUserFollowRelation crmUserFollowRelation) {
        return toAjax(crmUserFollowRelationService.updateCrmUserFollowRelation(crmUserFollowRelation));
    }

    /**
     * 删除用户跟进关系
     */
    @Operation(summary = "删除用户跟进关系")
    @PreAuthorize("@ss.hasPermi('system:relation:remove')")
    @Log(title = "用户跟进关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crmUserFollowRelationService.deleteCrmUserFollowRelationByIds(ids));
    }
}
